/*
 * File     : LargeParameter32.java
 * Created  : 1 May 2011
 *
 * Copyright © 2011 Matthew Wilson (mj. {my-surname} .uk {at} gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.dni.internal.call;

import java.util.List;

import org.objectweb.asm.MethodVisitor;


/**
 * Special parameter implementation for passing parameters through a buffer.
 * Used when the number of parameters exceeds a limit.  All parameters are
 * passed as 32-bit (and 64-bit as two 32-bit).
 *
 * @author Matthew Wilson
 */
final class LargeParameter32 extends AbstractLargeParameter
{

    private final int words;


    /**
     * @param parameters
     *            the parameters to send
     */
    LargeParameter32( final List< Parameter > parameters )
    {
        super( parameters );

        int wordsTemp = 0;
        for ( Parameter parameter : parameters )
        {
            if ( parameter.getNativeType() == 'J' ||
                 parameter.getNativeType() == 'D' )
            {
                wordsTemp++;
            }
            wordsTemp++;
        }
        this.words = wordsTemp;

        setNativeTypeAsPointer();
        assert getNativeType() == 'I';
    }

    /**
     * @return the number of 32-bit words used
     */
    @Override
    int getWords()
    {
        return this.words;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    void writePrepareParameter( final MethodVisitor methodVisitor )
    {
        // TODO v1.1 large parameter support
        throw new UnsupportedOperationException( "FIXME" );
    }

}
